﻿using System;
using System.Collections.Generic;
using System.Text;
using NHibernateMappingSample.Entities;
using RepositorySample.Interfaces;

namespace RepositorySample.BusinessLayer
{
   public class ShippingCostCalculator
   {
      private IOrdersRepository _repository;
      private const string Cargo5 = "CARGO TRANSPORT 5";
      private const string FEDEX = "FEDEX";

      public ShippingCostCalculator(IOrdersRepository _repository)
      {
         this._repository = _repository;
      }

      public Decimal CalculateShipping(int orderID)
      {
         SalesOrderHeader order = _repository.Load(orderID);
         decimal shippingCost = 0.0m;
         //A very simple shipping calculator
         switch(order.ShipMethod)
         {
            case FEDEX:
               if(order.TotalDue > 100m)
               {
                  shippingCost = order.TotalDue*0.02m;
               }
               else
               {
                  shippingCost = order.TotalDue*0.05m;
               }
               break;
            case Cargo5:
               shippingCost = 10.5m;
               break;
         }
         return shippingCost;
      }
   }
}
